import {ConfigType, ScannerResult} from "../types";
import {JavaScanner} from "../scanner/scanners/JavaScanner";
import {NpmScanner} from "../scanner/scanners/NpmScanner";
import {UniappScanner} from "../scanner/scanners/UniappScanner";
import {PythonScanner} from "../scanner/scanners/PythonScanner";
import {CSharpScanner} from "../scanner/scanners/CSharpScanner";
import {MergeUtil} from "../utils/MergeUtil";

export const defaultConfig: ConfigType = {
  server: {
    // 服务器端口
    port: 3000,
  },
  // 扫描选项
  scan: {
    targetDir: '.',
    // 扫描深度
    depth: 3,
    // 排除扫描
    excludes: [
      '**/node_modules/**',
      '**/.git/**',
      '**/dist/**',
      '**/build/**',
      '**/target/**',
      '**/out/**',
      '**/.vscode/**',
      '**/.idea/**',
      '**/.next/**',
      '**/coverage/**'
    ],
    // 项目类型映射
    projectTypes: {
      npm: {
        // 主体文件
        mains: ['package.json'],
        // 图标
        icon: '📦',
        // 项目类型颜色
        color: '#CB3837', // NPM标准红色
        scanner: NpmScanner
      },
      java: {
        mains: ['pom.xml', 'build.gradle'],
        icon: '☕',
        color: '#B07219', // Java棕色
        scanner: JavaScanner
      },
      uniapp: {
        mains: ['manifest.json'],
        icon: '🎯',
        color: '#2B9939', // UniApp绿色
        scanner: UniappScanner
      },
      python: {
        mains: ['setup.py', 'requirements.txt', 'Pipfile', 'pyproject.toml'],
        icon: '🐍',
        color: '#3572A5', // Python蓝色
        scanner: PythonScanner
      },
      csharp: {
        mains: ['.csproj', '.sln'],
        icon: '🔷',
        color: '#178600', // C#绿色
        scanner: CSharpScanner
      }
    }
  }
}

class GlobalConfig {
  private static instance: GlobalConfig;
  private _config: ConfigType = defaultConfig;

  public get config() {
    return this._config;
  }

  public mergeConfig(config: Partial<ConfigType>) {
    MergeUtil.deepMerge(this._config, config);
  }
}

export const globalConfig = new GlobalConfig();
